'''
Created on 23/09/2010

Data models specification

@author: fccoelho
'''
import datetime
from google.appengine.ext import db
from google.appengine.api import users

class Member(db.Model):
    user = db.UserProperty(required=True)
    member_since = db.DateProperty(auto_now_add=True)
    location = db.GeoPtProperty()

class Corpus(db.Model):
    name = db.StringProperty(required=True)
    Owner = db.ReferenceProperty(Member,required = True, verbose_name="My corpora", collection_name="my_corpora")
    public = db.BooleanProperty(required=True)
    creation_date = db.DateProperty(auto_now_add=True)
    last_updated = db.DateProperty(auto_now=True)

class Document(db.Model):
    name = db.StringProperty(required=True)
    corpus = db.ReferenceProperty(Member,required=True,verbose_name="Documents",collection_name="documents")
    owner = db.ReferenceProperty(Member,required = True, verbose_name="My models", collection_name="my_models")
    source = db.TextProperty(required=True)
    last_updated = db.DateProperty(auto_now=True)
    public = db.BooleanProperty(required=True)
    rating = db.RatingProperty()

Member.shared_with_me = db.ReferenceProperty(Document,verbose_name="Models Shared with me", collection_name="shared_with" )
## Stats related tables

class Session(db.Model):
    '''
    Statistics about use sessions
    '''
    date = db.DateProperty(auto_now_add=True)
    member = db.ReferenceProperty(Member, required=True, collection_name="sessions")
    duration = db.IntegerProperty(required=True)
    document = db.ReferenceProperty(Document, collection_name="sessions")
    
class Install(db.Model):
    '''
    Data about unique installs
    '''
    date = db.DateProperty(auto_now_add=True)
    version = db.StringProperty(required=True)
    opsys = db.StringProperty(required=True,verbose_name='Operating-System')